<template>
	<div class="content">
		<Table stripe :columns="columns" :data="configList" ref="table" :loading="loading"></Table>
		<Modal v-model="modal1" title="修改配置" width='40%' :mask-closable="false">
			<Form :model="edit" :rules="rules" ref="editForm" :label-width="100">
				<FormItem label="用户等级" prop="levelId">
					<Input class="w-50" v-model="edit.descContent" disabled />
				</FormItem>
				<FormItem label="直推N个有效用户" prop="pushNum" v-if="edit.levelId != 1">
					<Input class="w-50" v-model="edit.pushNum" placeholder="请输入直推有效用户数量" />
				</FormItem>
				<FormItem label="N节内团队人数" prop="layer" v-if="edit.levelId != 1">
					<Input class="w-50" v-model="edit.layer" placeholder="请输入节内的团队人数" />
					<!--<p>
						<font color="#ed4014">*不判断值为-1,切记不能为0</font>
					</p>-->
				</FormItem>
				<FormItem label="团队人数" prop="teamNum" v-if="edit.levelId != 1">
					<Input class="w-50" v-model="edit.teamNum" placeholder="请输入团队数量" />
				</FormItem>
				<FormItem label="每天最多可刷单N次" prop="maxBuyNum">
					<Input class="w-50" v-model="edit.maxBuyNum" placeholder="请输入每天最多刷单次数" />
				</FormItem>
				<FormItem label="每天释放封顶数量" prop="upperLimit">
					<Input class="w-50" v-model="edit.upperLimit" placeholder="请输入封顶数量" />
				</FormItem>
				<FormItem label="附加条件" prop="otherCondition" v-if="edit.otherCondition != -1">
					<Input class="w-50" v-model="edit.otherCondition" placeholder="请输入附加条件数量" />
					<p>
						<font color="#adadad" v-if="edit.levelId == 7">*社区节点,推荐<span v-text="edit.otherCondition == '' ? '0' : edit.otherCondition"></span>个四星</font>
						<font color="#adadad" v-if="edit.levelId == 8">*超级节点,推荐<span v-text="edit.otherCondition == '' ? '0' : edit.otherCondition"></span>个社区节点</font>
					</p>
				</FormItem>
				<FormItem label="动态收益" prop="teamRatio" v-if="edit.levelId == 8 || edit.levelId == 7">
					<Input class="w-50" v-model="edit.teamRatio" placeholder="如:0.25" />
					<p>
						<font color="#adadad">*社区节点的动态收益，团队所有会员手续费的百分比：25% 写成 0.25</font>
					</p>
				</FormItem>
				<FormItem label="超级节点收益" prop="allRatio" v-if="edit.levelId == 8">
					<Input class="w-50" v-model="edit.allRatio" placeholder="如:0.25" />
					<p>
						<font color="#adadad">*超级节点持有的动态收益，全网会员手续费的百分比：25% 写成 0.25</font>
					</p>
				</FormItem>
				<FormItem label="创建时间" prop="createTime">
					<Input class="w-50" v-model="edit.createTime" placeholder="" disabled />
				</FormItem>
			</Form>
			<div slot="footer">
				<Button type="text" size="large" @click="modal1 = false;">取消</Button>
				<Button type="primary" size="large" @click="editSubmit" :loading="Btnloading">确定</Button>
			</div>
		</Modal>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				pageSize: 1000,
				configList: [],
				modal1: false,
				loading: true,
				Btnloading: false,
				edit: {
					levelId: '',
					pushNum: '',
					layer: '',
					teamNum: '',
					maxBuyNum: '',
					upperLimit: '',
					otherCondition: '',
					teamRatio: '',
					allRatio: '',
					createTime: '',
				},
				rules: {
					pushNum: [{
						required: true,
						message: '直推实名认证用户数量不能为空',
						trigger: 'blur',
					}],
					layer: [{
						required: true,
						message: "节内的团队人数不能为空",
						trigger: "blur"
					}],
					teamNum: [{
						required: true,
						message: "团队数量不能为空",
						trigger: "blur"
					}],
					maxBuyNum: [{
						required: true,
						message: "每天最多刷单次数不能为空",
						trigger: "blur"
					}],
					upperLimit: [{
						required: true,
						message: "封顶数量不能为空",
						trigger: "blur"
					}],
					otherCondition: [{
						required: true,
						message: "附加条件不能为空",
						trigger: "blur"
					}],
					teamRatio: [{
						required: true,
						message: "社区节点和超级节点的动态收益,团队所有会员手续费的百分比不能为空",
						trigger: "blur"
					}],
					allRatio: [{
						required: true,
						message: "超级节点持有的动态收益，全网会员手续费的百分比不能为空",
						trigger: "blur"
					}],
				},
				columns: [{
						title: '用户等级',
						key: 'descContent',
						align: "center",
					},
					{
						title: '描述',
						key: 'descContent',
						align: "center",
					},
					{

						title: '操作',
						key: 'action',
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h(
									'Button', {
										props: {
											type: 'primary',
											size: 'small',
										},
										style: {
											marginRight: '5px'
										},
										on: {
											click: () => {
												this.$refs["editForm"].resetFields();
												this.modal1 = true;
												this.axios.get('/admin/settings/level/getlist').then(res => {
													if(res.data.code == 200) {
														this.edit = res.data.data[params.index];
														//														this.edit.pushNum = this.edit.pushNum.toString();
														this.edit.createTime = this.stringToTime(this.edit.createTime);
													}
												})
											}
										}
									},
									'编辑'
								),
							])
						}

					}
				]
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			});
			this.getConfig(); // 其他配置查询
		},
		methods: {
			getConfig() { // 其他配置查询
				this.axios.get('/admin/settings/level/getlist').then(res => {
					if(res.data.code == 200) {
						this.configList = res.data.data;
						this.loading = false;
					}
				})
			},
			editSubmit() {
				this.$refs.editForm.validate(valid => {
					// 表单验证
					if(valid) {
						this.Btnloading = true;
						let params = this.qs.stringify({
							id: this.edit.id,
							levelId: this.edit.levelId,
							pushNum: this.edit.pushNum,
							layer: this.edit.layer,
							teamNum: this.edit.teamNum,
							maxBuyNum: this.edit.maxBuyNum,
							upperLimit: this.edit.upperLimit,
							otherCondition: this.edit.otherCondition,
							teamRatio: this.edit.teamRatio,
							allRatio: this.edit.allRatio,
						})
						this.axios.put('/admin/settings/level/config', params).then(res => {
							if(res.data.code == 200) {
								this.Btnloading = false;
								this.$Message.info(res.data.msg);
								this.modal1 = false;
								this.getConfig();
								this.edit = {
									levelId: '',
									pushNum: '',
									layer: '',
									teamNum: '',
									maxBuyNum: '',
									upperLimit: '',
									otherCondition: '',
									teamRatio: '',
									allRatio: '',
									createTime: '',
								}
							}
						}).catch(err => {
							this.$Message.info('系统错误');
							this.Btnloading = false;
						})
					}
				});
			},
		}
	}
</script>

<style lang="less" scoped>
	.p-10 {
		padding-top: 0 !important;
		padding-left: 50px !important;
	}
	
	.w50 {
		width: 50px !important;
	}
	
	.w25 {
		width: 25px !important;
	}
	
	.w120 {
		width: 120px !important;
	}
	
	.mar {
		margin-left: 5px;
	}
	
	.pl-100 {
		padding-left: 100px;
	}
</style>